import { action, computed, observable, configure, autorun } from 'mobx';
import axios from 'axios';

class Mobx {
    @observable list = [];
    @observable iptVal = '';

    @computed get total () {
        return this.list.length;
    }

    @action.bound changeVal (val) {
        this.iptVal = val;
    }

    @action.bound increment (val) {
        this.list.push(val);
    }

    @action.bound async initList () {
        const res = await axios({ url: 'http://localhost:8888' });
        this.setList(res.data);
    }

    @action.bound setList (data) {
        this.list = data;
    }

    @action.bound decrement (val) {
        this.list = this.list.filter((item, idx) => idx !== val);
    }
}

const store = new Mobx();

configure({
    enforceActions: 'always'
});

export default store;
